# Maintainer: Diego Sogari <diego.sogari@falker.com.br>

_realname=laszip
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.4.3
pkgrel=1
pkgdesc="Free and lossless LiDAR compression (mingw-w64)"
arch=('any')
url="https://www.laszip.org/"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
source=(https://github.com/LASzip/LASzip/releases/download/${pkgver}/laszip-src-${pkgver}.tar.gz
        "${_realname}-3.1.1.patch"
        "laszip-3.4.3-mingw-utf8.patch")
sha256sums=('53f546a7f06fc969b38d1d71cceb1862b4fc2c4a0965191a0eee81a57c7b373d'
            'c3d98f0bb85bb78e8cd31e1578799ed2ebda67b567a96c07d22b6eb2c9f208ef'
            '1edee63baedcd020e9cbeb2e4d52741b97f8a029ee52d48199f4930308c59c60')

prepare() {
  cd "${srcdir}/${_realname}-src-${pkgver}"
  patch -Np1 -i "${srcdir}/${_realname}-3.1.1.patch"
  patch -Np1 -i "${srcdir}/laszip-3.4.3-mingw-utf8.patch"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "../${_realname}-src-${pkgver}"

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
